package com.jch.dm.chapter_16_mediator;

import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * @author: Administrator
 * @create: 2020/04/07 14:29
 **/
public class ColleagueCheckbox extends Checkbox implements ItemListener,Colleague {

    private Mediator mediator;

    /**
     * Creates a check box with the specified label, in the specified
     * check box group, and set to the specified state.
     *
     * @param caption a string label for this check box,
     *              or <code>null</code> for no label.
     * @param group a check box group for this check box,
     *              or <code>null</code> for no group.
     * @param state the initial state of this check box.
     * @throws HeadlessException if
     *                           <code>GraphicsEnvironment.isHeadless</code>
     *                           returns <code>true</code>
     * @see GraphicsEnvironment#isHeadless
     * @since JDK1.1
     */
    public ColleagueCheckbox(String caption, CheckboxGroup group, boolean state) throws HeadlessException {
        super(caption, group, state);
    }

    /**
     * 设置仲裁者
     *
     * @param mediator
     */
    @Override
    public void setMediator(Mediator mediator) {
        this.mediator=mediator;
    }

    /**
     * 设置组员禁用启用
     *
     * @param enabled
     */
    @Override
    public void setColleagueEnabled(boolean enabled) {
        setEnabled(enabled);
    }

    /**
     * Invoked when an item has been selected or deselected by the user.
     * The code written for this method performs the operations
     * that need to occur when an item is selected (or deselected).
     *
     * @param e
     */
    @Override
    public void itemStateChanged(ItemEvent e) {
        mediator.colleagueChanged();
    }
}
